﻿using Spire.Doc.Documents;
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Spire.Doc;
using System.Drawing;

namespace slwhTools.IConverter
{
    public class WordConverterService: IConverter
    {
        // Word转PDF
        public static void ConvertWordToPdf(string wordPath, string pdfPath)
        {
            Document document = new Document();
            document.LoadFromFile(wordPath);
            document.SaveToFile(pdfPath, FileFormat.PDF);
        }

        // Word转图片（每页一张图片）
        public static void ConvertWordToImages(string wordPath, string outputFolder)
        {
            Document document = new Document();
            document.LoadFromFile(wordPath);

            // 将每一页保存为图片
            Image[] images = document.SaveToImages(ImageType.Bitmap);

            for (int i = 0; i < images.Length; i++)
            {
                string imagePath = Path.Combine(outputFolder, $"page_{i + 1}.png");
                images[i].Save(imagePath, ImageFormat.Png);
            }
        }
    }
}
